import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart';
import 'package:xbxxz_assistant/data/drug_land_data.dart';

class DrugLandPage extends StatefulWidget {
  @override
  _DrugLandPageState createState() => _DrugLandPageState();
}

class _DrugLandPageState extends State<DrugLandPage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("丹药材料(凡品)"),
      ),
      body: Container(
        constraints: BoxConstraints.expand(),
        color: Colors.brown,
        child: SingleChildScrollView(
//        scrollDirection: Axis.horizontal,
          child: Column(
            children: <Widget>[
              for (var item in _buildTable())
                Card(
                  color: Color.fromRGBO(220, 200, 160, 1.0),
                  elevation: 10.0,
                  shape: const RoundedRectangleBorder(
                      borderRadius:
                          BorderRadius.all(Radius.circular(14.0))), //设置圆角
                  child: Padding(
                    padding: const EdgeInsets.all(8.0),
                    child: item,
                  ),
                ),
            ],
          ),
        ),
      ),
    );
  }

  List<Widget> _buildTable() {
    List<Widget> widgetItems = List();
    drugLandData.forEach((k, v) {
      var title = Text(k);
      widgetItems.add(title);
      var table = Table(
        columnWidths: {
          0: IntrinsicColumnWidth(),
          1: IntrinsicColumnWidth(),
          2: IntrinsicColumnWidth(),
          3: IntrinsicColumnWidth(),
          4: IntrinsicColumnWidth(),
          5: IntrinsicColumnWidth(),
        },
        border: TableBorder.symmetric(
            inside: BorderSide(
                color: Colors.black12, width: 1.0, style: BorderStyle.solid)),
        children: [
          TableRow(
            children: [
              TableCell(
                child: Center(child: Text("材料品级")),
              ),
              TableCell(
                child: Center(child: Text("何首乌")),
              ),
              TableCell(
                child: Center(child: Text("人参")),
              ),
              TableCell(
                child: Center(child: Text("血精草")),
              ),
              TableCell(
                child: Center(child: Text("加属性")),
              ),
              TableCell(
                child: Center(child: Text("丹方来源")),
              ),
            ],
          ),
          for (var item in v)
            TableRow(
              children: [
                TableCell(
                  child: Center(child: Text(item["品级"])),
                ),
                TableCell(
                  child: Center(child: Text(item["何首乌"])),
                ),
                TableCell(
                  child: Center(child: Text(item["人参"])),
                ),
                TableCell(
                  child: Center(child: Text(item["血精草"])),
                ),
                TableCell(
                  child: Center(child: Text(item["加属性"])),
                ),
                TableCell(
                  child: Center(child: Text(item["丹方来源"])),
                ),
              ],
            ),
        ],
      );
      widgetItems.add(table);
    });
    return widgetItems;
  }

  @override
  void initState() {
    super.initState();
  }
}
